HAL TIM control functions migration

This section provides information about the HAL TIM control functions migration.

HAL TIM base init function

HAL1

HAL2

Initialization mode

  • In HAL1 to Initialize and to configure the TIM base you need to call:

    • HAL_TIM_Base_Init(&htim).

  • In HAL2 just replace it with the following sequence:

    • HAL_TIM_Init(&htim, HAL_TIMi) to link between the handle and the instance.

    • HAL_TIM_SetConfig(&htim, &p_config) to set the basic time base configuration.


HAL TIM PWM init function

HAL1

HAL2

Initialization mode

  • In HAL1 to Initialize and to configure the TIM PWM you need to call:

    • HAL_TIM_PWM_Init(&htim).

  • In HAL2 just replace it with the following sequence:

    • HAL_TIM_Init(&htim, HAL_TIMi) to link between the handle and the instance.

    • HAL_TIM_SetConfig(&htim, &p_config) to set the basic time base configuration.


HAL TIM Output compare init function

HAL1

HAL2

Initialization mode

  • In HAL1 to initialize and to configure the TIM Output Compare Time base you need to call:

    • HAL_TIM_OC_Init(&htim).

  • In HAL2 just replace it with the following sequence:

    • HAL_TIM_Init(&htim, HAL_TIMi) to link between the handle and the instance.

    • HAL_TIM_SetConfig(&htim, &p_config) to set the basic time base configuration.


HAL TIM input capture init function

HAL1

HAL2

Initialization mode

  • In HAL1 to Initialize and to configure the TIM Input Capture Time base you need to call:

    • HAL_TIM_IC_Init(&htim).

  • In HAL2 just replace it with the following sequence:

    • HAL_TIM_Init(&htim, HAL_TIMi) to link between the handle and the instance.

    • HAL_TIM_SetConfig(&htim, &p_config) to set the basic time base configuration.


HAL TIM one pulse init function

HAL1

HAL2

Initialization mode

  • In HAL1 to configure the TIM one pulse initialization you need to call:

    • HAL_TIM_OnePulse_Init.

  • In HAL2 just replace it with the following sequence:

    • HAL_TIM_Init

    • HAL_TIM_SetConfig

    • HAL_TIM_EnableOnePulseMode or HAL_TIM_DisableOnePulseMode according to one pulse mode selected.


HAL TIM encoder initialization function

HAL1

HAL2

Initialization mode

  • In HAL1 to configure the TIM encoder initialization you need to call:

    • HAL_TIM_Encoder_Init.

  • In HAL2, follow the next sequence to get the same behavior as HAL1:

    • HAL_TIM_Init

    • HAL_TIM_SetConfig

    used to set the basic config additionally to the encoder mode. Followed by :

    • HAL_TIM_IC_SetConfigChannel

    • HAL_TIM_IC_SetConfigCaptureUnit

    used for the channel x configuration.


HAL TIM hall sensor initialization function

HAL1

HAL2

Initialization mode

  • In HAL1 to Initialize the TIM Hall Sensor Interface you need to call:

    • HAL_TIMEx_HallSensor_Init.

  • In HAL2, to get the same behavior, just replace it with the following sequence:

    • HAL_TIM_Init

    • HAL_TIM_SetConfig

    • HAL_TIM_IC_SetConfigChannel

    • HAL_TIM_IC_SetConfigCaptureUnit

    • HAL_TIM_IC_EnableXORGate

    • HAL_TIM_OC_SetConfigCompareUnit

    • HAL_TIM_OC_SetConfigChannel

    • HAL_TIM_SetSynchroSlave

    • HAL_TIM_SetTriggerOutput


HAL TIM get active channel function

HAL_TIM_GetActiveChannel function is used to determine which channel of a timer is currently active. This function is particularly useful in interrupt service routines (ISRs) or callback functions where you need to handle different timer channels distinctly.

Function

HAL1

HAL2

HAL_TIM_GetActiveChannel

Removed because the channel is added as an argument for each callback function which depends on the channel.

Example

HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);

HAL_TIM_InputCaptureCallback(hal_tim_handle_t *htim, hal_tim_channel_t channel);


HAL TIMEx get channel state function

HAL1

HAL2

HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim, uint32_t ChannelN);
hal_tim_channel_state_t HAL_TIM_GetChannelState(const hal_tim_handle_t *htim, hal_tim_channel_t channel);

HAL TIM IC channel configuration function

HAL1

HAL2

channel configuration function

  • In HAL1 to configure a channel in input mode you need to call:

    • HAL_TIM_IC_ConfigChannel.

  • In HAL2 just replaced by the following sequence:

    • HAL_TIM_IC_SetConfigChannel

    • HAL_TIM_IC_SetConfigCaptureUnit


HAL TIM commutation event functions

HAL1

HAL2

Polling mode

  • In HAL1 to configure the TIM commutation event sequence in polling mode you need to call:

    • HAL_TIMEx_ConfigCommutEvent.

  • In HAL2 just replaced by the following sequence:

    • HAL_TIM_EnableCommutation

    • HAL_TIM_Start

Interrupt mode

  • In HAL1 to configure the TIM commutation event sequence in interrupt mode you need to call:

    • HAL_TIMEx_ConfigCommutEvent_IT.

  • In HAL2 just replaced by the following sequence:

    • HAL_TIM_EnableCommutation

    • HAL_TIM_Start_IT_Opt(htim, HAL_TIM_OPT_IT_COMMUTATION)

DMA mode

  • In HAL1 to configure the TIM commutation event sequence in DMA mode you need to call:

    • HAL_TIMEx_ConfigCommutEvent_DMA.

  • In HAL2 just replaced by the following sequence:

    • HAL_TIM_EnableCommutation

    • HAL_TIM_Start_DMA

Note

In HAL1, the function HAL_TIMEx_ConfigCommutEvent/IT/DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) requires three arguments. When the CommutationSource is set to TIM_COMMUTATION_SOFTWARE , the InputTrigger must be TIM_TS_NONE . In HAL2, the implementation changes to HAL_TIM_EnableCommutation, which no longer requires specifying the InputTrigger for any selected commutation_source. Consequently, TIM_TS_NONE is removed from HAL2..


HAL TIM master mode configuration

HAL1

HAL2

Master Mode Configuration

  • In HAL1, to configure the TIM in master mode, the following function is used:

    • HAL_TIMEx_MasterConfigSynchronization

  • In HAL2, the configuration is handled by the following functions:

    • HAL_TIM_SetTriggerOutput

    • HAL_TIM_SetTriggerOutput2

    • HAL_TIM_EnableMasterSlaveMode


HAL TIM TI1 input configuration

HAL1

HAL2

TI1 Input Configuration

  • In HAL1, the TI1 input configuration is handled by the following function:

    • HAL_TIM_ConfigTI1Input This function is used to select the signal connected to the TI1 input: direct from CH1_input or a XOR combination between CH1_input, CH2_input & CH3_input.

  • In HAL2, the TI1 input configuration is handled by the following functions:

    • HAL_TIM_IC_EnableXORGate This function enables the XOR gate between CH1_input, CH2_input & CH3_input.

    • HAL_TIM_IC_DisableXORGate This function disables the XOR gate and directly connects TI1 input from CH1_input.


HAL TIMEx TI selection function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_TISelection(TIM_HandleTypeDef *htim, uint32_t TISelection, uint32_t Channel);
hal_status_t HAL_TIM_IC_SetChannelSource(hal_tim_handle_t *htim, hal_tim_channel_t channel, hal_tim_channel_src_t channel_src);

HAL TIM OCREF clear configuration

HAL1

HAL2

OCREF Clear Configuration

  • In HAL1, the OCREF clear configuration is handled by the following function:

    • HAL_TIM_ConfigOCrefClear

  • In HAL2, the OCREF clear configuration is handled based on the source:

    • If ETR is used as the OCREF source:

      • HAL_TIM_SetExternalTriggerInput

      • HAL_TIM_SetOCRefClearSource

      • HAL_TIM_EnableChannelOCRefClear

    • Else:

      • HAL_TIM_SetOCRefClearSource

      • HAL_TIM_EnableChannelOCRefClear


HAL TIM OC pulse on compare configuration

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_OC_ConfigPulseOnCompare(TIM_HandleTypeDef *htim, uint32_t PulseWidthPrescaler, uint32_t PulseWidth);
hal_status_t HAL_TIM_OC_SetPulseGenerator(hal_tim_handle_t *htim, const hal_tim_pulse_generator_config_t *p_config);

HAL TIM One pulse configuration

HAL1

HAL2

One Pulse Configuration

  • In HAL1, the one pulse configuration is handled by the following function:

    • HAL_TIM_OnePulse_ConfigChannel

  • In HAL2, the one pulse configuration is handled by the following functions:

    • HAL_TIM_OC_SetConfigCompareUnit

    • HAL_TIM_OC_SetConfigChannel

    • HAL_TIM_IC_SetConfigCaptureUnit

    • HAL_TIM_IC_SetConfigChannel

    • HAL_TIM_SetSynchroSlave


HAL TIM encoder index configuration functions

HAL1

HAL2

Configuration mode

  • In HAL1 to configure the TIM encoder index you need to call:

    • HAL_TIMEx_ConfigEncoderIndex.

  • In HAL2 just replace by the following sequence:

    • HAL_TIM_SetExternalTriggerInput

    • HAL_TIM_SetConfigEncoderIndex


HAL TIM enable disable encoder first index functions

HAL1

HAL2

Configuration mode

  • In HAL1 to enable or disable the TIM encoder first index you need to call:

    • HAL_TIMEx_EnableEncoderFirstIndex.

    • HAL_TIMEx_DisableEncoderFirstIndex.

  • In HAL2, the configuration is part of the function:

    • HAL_TIM_SetConfigEncoderIndex


HAL TIM enable encoder index function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_EnableEncoderIndex(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_EnableEncoderIndex(hal_tim_handle_t *htim);

HAL TIM disable encoder index function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_DisableEncoderIndex(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_DisableEncoderIndex(hal_tim_handle_t *htim);

HAL TIM encoder index callback

HAL1

HAL2

void HAL_TIMEx_EncoderIndexCallback(TIM_HandleTypeDef *htim);
void HAL_TIM_EncoderIndexCallback(hal_tim_handle_t *htim);

HAL TIM Remap Configuration function

HAL1

HAL2

Configuration mode

  • In HAL1 to configure the TIM remap you need to call:

    • HAL_TIMEx_RemapConfig.

  • In HAL2, the configuration is done in the function along with other configurations:

    • HAL_TIM_SetExternalTriggerInput


HAL TIM Output Compare Channel Configuration functions

HAL1

HAL2

Configuration mode

  • In HAL1 to configure the TIM output compare channel you need to call:

    • HAL_TIM_OC_ConfigChannel.

  • In HAL2 just replace by the following sequence:

    • HAL_TIM_OC_SetConfigChannel

    • HAL_TIM_OC_SetConfigCompareUnit


HAL TIM group channel 5 function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels);
hal_status_t HAL_TIM_OC_SetGroupChannel(hal_tim_handle_t *htim, uint32_t group);

HAL TIM break input arm/disarm functions

HAL1

HAL2

Break Input Control

  • In HAL1 to rearm the designated break input you need to call:

    • HAL_TIMEx_ReArmBreakInput.

  • To disarm the designated break input you need to call:

    • HAL_TIMEx_DisarmBreakInput.

  • In HAL2, both functions can be replaced by a single function:

    • HAL_TIM_BREAK_RearmInput


HAL TIM slave configuration functions

HAL1

HAL2

Blocking Mode

  • In HAL1, to configure the TIM in Slave mode we need to call:

    • HAL_TIM_SlaveConfigSynchro

  • In HAL2, it is handled by:

    • HAL_TIM_SetSynchroSlave: to select the slave mode and the input trigger.

    • Then according to the input trigger selected, call the appropriate function:

      • If Internal Trigger ITRx is selected, there is no configuration to do.

      • If ETRF is selected, the function HAL_TIM_SetExternalTriggerInput is called.

      • If the trigger is TI1F_ED, TI1FP1 or TI2FP2, the functions HAL_TIM_IC_SetConfigChannel and HAL_TIM_IC_SetConfigCaptureUnit are called.

    • Finally to start in blocking mode: HAL_TIM_Start

Interrupt Mode

  • In HAL1, it is handled by the following functions:

    • To configure: HAL_TIM_SlaveConfigSynchro_IT

  • In HAL2, it is handled by:

    • HAL_TIM_SetSynchroSlave: to select the slave mode and the input trigger.

    • Then according to the input trigger selected, call the appropriate function:

      • If Internal Trigger ITRx is selected, there is no configuration to do.

      • If ETRF is selected, the function HAL_TIM_SetExternalTriggerInput is called.

      • If the trigger is TI1F_ED, TI1FP1 or TI2FP2, the functions HAL_TIM_IC_SetConfigChannel and HAL_TIM_IC_SetConfigCaptureUnit are called.

    • Finally to start in interrupt mode: HAL_TIM_Start_IT_Opt(htim, HAL_TIM_OPT_IT_TRIGGER_INPUT)


HAL TIM enable slave mode preload functions

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_ConfigSlaveModePreload(TIM_HandleTypeDef *htim, uint32_t Source);
HAL_StatusTypeDef HAL_TIMEx_EnableSlaveModePreload(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_EnableSlaveModePreload(hal_tim_handle_t *htim, const hal_tim_slave_mode_preload_src_t preload_src);

HAL TIM disable slave mode preload functions

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_DisableSlaveModePreload(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_DisableSlaveModePreload(hal_tim_handle_t *htim);

HAL TIM SW event generation

HAL1

HAL2

HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim,
                                        uint32_t EventSource);
hal_status_t HAL_TIM_GenerateEvent(hal_tim_handle_t *htim,
                                   hal_tim_sw_event_id_t sw_event_id);

HAL TIMEx enable HSE32 functions

HAL1

HAL2

Configuration

  • In HAL1 to enable HSE32 you need to call:

    • HAL_TIMEx_EnableHSE32.

  • In HAL2 it is removed and to get the functionality you need to call the function:

    • HAL_TIM_IC_SetConfigChannel

    And to select the source from the structure hal_tim_ic_channel_config_t:

    • HAL_TIM_INPUT_TIM17_TI1_HSE_DIV32 or HAL_TIM_INPUT_TIM16_TI1_HSE_DIV32 according to the timer selected at the beginning.

Note

to disable HSE32 you need to select another input source.


HAL TIMEx config break dead time functions

HAL1

HAL2

Configuration

  • In HAL1 the configuration of the Break feature, dead time, Lock level, OSSI/OSSR State, and the AOE (automatic output enable) is done with one function:

    • HAL_TIMEx_ConfigBreakDeadTime.

  • In HAL2 this function is split into multiple functions where each function handles a specific functionality:

    • HAL_TIM_BREAK_SetConfigInput

    • HAL_TIM_BREAK_EnableInput

    • HAL_TIM_SetDeadtime

    • HAL_TIM_BREAK_SetOutputOffStates

    • HAL_TIM_SetLockLevel

    • HAL_TIM_BREAK_EnableAutomaticOutput


HAL TIMEx config break input source functions

HAL1

HAL2

Initialization mode

  • In HAL1 to configure the Break input source you need to call:

    • HAL_TIMEx_ConfigBreakInput.

  • In HAL2 this function is split into multiple functions where each function handles a specific functionality:

    • HAL_TIM_BREAK_EnableInputSource:to enable the input source selected.

    • HAL_TIM_BREAK_SetInputSourcePolarity:to set the polarity.


HAL TIMEx config dead time functions

HAL1

HAL2

Initialization mode

  • In HAL1 to configure the dead time you need to call:

    • HAL_TIMEx_ConfigDeadTime: to Configure deadtime

    • HAL_TIMEx_ConfigAsymmetricalDeadTime: to Configure asymmetrical deadtime

  • In HAL2 these functions are regrouped into one function:

    • HAL_TIM_SetDeadtime


HAL TIM enable deadtime preload function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_EnableDeadTimePreload(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_EnableDeadtimePreload(hal_tim_handle_t *htim);

HAL TIM disable deadtime preload function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_DisableDeadTimePreload(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_DisableDeadtimePreload(hal_tim_handle_t *htim);

HAL TIM enable asymmetrical deadtime function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_EnableAsymmetricalDeadTime(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_EnableAsymmetricalDeadtime(hal_tim_handle_t *htim);

HAL TIM disable asymmetrical deadtime function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_DisableAsymmetricalDeadTime(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_DisableAsymmetricalDeadtime(hal_tim_handle_t *htim);

HAL TIM enable dithering function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_DitheringEnable(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_EnableDithering(hal_tim_handle_t *htim);

HAL TIM disable dithering function

HAL1

HAL2

HAL_StatusTypeDef HAL_TIMEx_DitheringDisable(TIM_HandleTypeDef *htim);
hal_status_t HAL_TIM_DisableDithering(hal_tim_handle_t *htim);

HAL TIM PWM channel configuration functions

HAL1

HAL2

Configuration mode

  • In HAL1 to initializes the TIM PWM channels according to the specified parameters you need to call:

    • HAL_TIM_PWM_ConfigChannel.

  • In HAL2 just replace by the following sequence:

    • HAL_TIM_OC_SetConfigChannel

    • HAL_TIM_OC_SetConfigCompareUnit

    • HAL_TIM_OC_EnableComparePreload

    • HAL_TIM_OC_EnableCompareFastMode or HAL_TIM_OC_DisableCompareFastMode according to the needed configuration.


HAL TIM read captured value function

HAL1

HAL2

uint32_t HAL_TIM_ReadCapturedValue(const TIM_HandleTypeDef *htim,
                                   uint32_t Channel);
uint32_t HAL_TIM_IC_ReadChannelCapturedValue(const hal_tim_handle_t *htim,
                                             hal_tim_channel_t channel)

HAL TIM config clock source

HAL1

HAL2

HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim,
                                            const TIM_ClockConfigTypeDef *sClockSourceConfig);
hal_status_t HAL_TIM_SetClockSource(hal_tim_handle_t *htim,
                                    const hal_tim_clock_sel_t *p_clk_sel);